package com.o2o.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {
	public static String getNow(){
		SimpleDateFormat smt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return smt.format(new Date());
	}
	public static String getNow(Date date){
		SimpleDateFormat smt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return smt.format(date);
	}
	
	public static Date getNowDate(){
		return new Date();
	}
	
	public static String GetStringTimeByStamp(String timestamp){
		long datatime= Long.parseLong(timestamp);
		Date date=new Date(datatime);
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
		String timeresult=format.format(date);
		return timeresult;
	}
	
	public static Date GetDateTimeByStamp(long timeStamp){
		Date date=new Date(timeStamp);
		return date;
	}
	
	/**
	 * 时间到时间戳的转换。注意时间是字符串格式。字符串与时间的相互转换
	 * @param time 时间是字符串格式
	 * @return 时间戳
	 */
	public String GetStampByTime(String time){
		String Stamp="";
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date;
		try{
			date=sdf.parse(time);
			Stamp=date.getTime()+"000";
		}catch(Exception e){
			e.printStackTrace();
		}
		return Stamp;
	}
}
